# coding=utf-8
# @Author:zcx
# @Time:2024/9/12 20:27
import sys
from PySide6.QtGui import QAction
from PySide6.QtWidgets import QApplication, QWidget, QVBoxLayout, QMenuBar

class MyWidget(QWidget):
    def __init__(self):
        super(MyWidget, self).__init__()
        self.setup_ui()

    def setup_ui(self):
        # 创建菜单栏
        menubar = QMenuBar(self)
        # 创建 文件 菜单
        fileMenu = menubar.addMenu('文件')

        # 添加动作到 文件 菜单
        action1 = QAction('新建标签页', self)
        fileMenu.addAction(action1)
        #添加快捷键
        action1.setShortcut("Ctrl+N")

        action2 = QAction('新建窗口', self)
        fileMenu.addAction(action2)
        # 添加快捷键
        action2.setShortcut("Ctrl+Shift+N")


        action3 = QAction('打开', self)
        fileMenu.addAction(action3)
        # 添加快捷键
        action3.setShortcut("Ctrl+O")

        action4 = QAction('保存', self)
        fileMenu.addAction(action4)
        # 添加快捷键
        action4.setShortcut("Ctrl+S")

        action5 = QAction('另存为', self)
        fileMenu.addAction(action5)
        # 添加快捷键
        action5.setShortcut("Ctrl+Shift+S")

        action6 = QAction('全部保存', self)
        fileMenu.addAction(action6)
        # 添加快捷键
        action6.setShortcut("Ctrl+Alt+S")

        # 添加分隔线
        fileMenu.addSeparator()

        action7 = QAction('页面设置', self)
        fileMenu.addAction(action7)

        action8 = QAction('打印', self)
        fileMenu.addAction(action8)
        # 添加快捷键
        action8.setShortcut("Ctrl+P")

        # 添加分隔线
        fileMenu.addSeparator()

        action9 = QAction('关闭选项卡', self)
        fileMenu.addAction(action9)
        # 添加快捷键
        action9.setShortcut("Ctrl+W")

        action10 = QAction('关闭窗口', self)
        fileMenu.addAction(action10)
        # 添加快捷键
        action10.setShortcut("Ctrl+Shift+W")

        action11 = QAction('退出', self)
        fileMenu.addAction(action11)


        # 创建 编辑 菜单
        editMenu = menubar.addMenu('编辑')
        copyAct = QAction("复制", self)
        cutAct = QAction('剪切', self)
        pasteAct = QAction('粘贴', self)
        copyAct.setShortcut("Ctrl+C")
        cutAct.setShortcut("Ctrl+X")
        pasteAct.setShortcut("Ctrl+V")
        editMenu.addActions([copyAct, cutAct, pasteAct])

        # 创建 查看 菜单
        viewMenu = menubar.addMenu('查看')
        ap = QAction("全屏", self)
        center = QAction("居中", self)
        left = QAction("居左", self)
        right = QAction("居右", self)
        viewMenu.addActions([ap, center, left, right])

        # 设置布局
        layout = QVBoxLayout(self)
        layout.addWidget(menubar)

        self.setGeometry(300, 300, 500, 300)
        self.setWindowTitle('Simple Menu Example')

if __name__ == '__main__':
    app = QApplication(sys.argv)
    myWidget = MyWidget()
    myWidget.show()
    sys.exit(app.exec())